let arr = (location.search).substring(1)
console.log(arr);

let item = arr.split("=")[1];
console.log(item);


let aul = document.querySelector("#lbtu .li-box");
console.log(aul);
let oul = document.querySelector("#product ul");
console.log(oul);

const xhr = new XMLHttpRequest();

xhr.open("get",`http://chst.vip:1234/api/getcouponproduct?couponid=${item}`);

xhr.send(null);

xhr.onreadystatechange = function(){
    if(xhr.readyState === 4){
        if(xhr.status === 200){
            let res = JSON.parse(xhr.responseText);
            // console.log(res.result[0]);
            console.log(res);
            // let regExp = /(?<=imgurl=)[^'"]*/;
            let ele = "";
            let ele2 = "";
            res.result.forEach(item => {
                // console.log(item);
                // var img = regExp.exec(item.productImg)[0];
                // var img = item.productImg;
                // console.log(img);
                ele += `<li>   
                            <a href="#">
                                ${item.couponProductImg}
                                <div class="li_box">
                                    <h3>${item.couponProductName}</h3>
                                    <p>${item.couponProductPrice}</p>
                                    <span>
                                        ${item.couponProductTime}
                                    </span>
                                </div>
                            </a>
                        </li>` ;
                ele2 +=`<li>${item.couponProductImg}</li>`
               
            });
            oul.innerHTML = ele;
            aul.innerHTML = ele2;
        }
    }
};


function LbtuInit(){
    $("body #lbtu").height(0).css("display","block")
}
//轮播图
function Lbtu(){
    let l = $(`body #lbtu ul .li-box li`).length
    console.log(aul);
    console.log(l);
    let num = 0;
    $("#product").click(function(){
        // console.log(1);
        let length = $("#product").height();
        // console.log(length);
        $("body #lbtu").height(length);
        $("body #lbtu").slideDown(function(){
            $("body #lbtu li:eq(0)").css("display","block").siblings().css("display","none");
            $("body #lbtu ul").css("display","block");
        })
    })
    $("#lbtu ul>span").click(function(){
        // console.log(2);
        $("#lbtu").slideUp()
    })
    //上一页按钮
    $("body #lbtu ul button:eq(0)").click(function(){
        num--;
        if(num<0){
            window.alert("当前是第一页")
            num = 0;
        }else{
            $(`body #lbtu li:eq(${num})`).css("display","block").siblings().css("display","none");
            console.log(num)
        }
    })
    //下一页按钮
    $("body #lbtu ul button:eq(1)").click(function(){
        num++;
        console.log(num)
        if(num<l){
            console.log(num)
            $(`body #lbtu li:eq(${num})`).css("display","block").siblings().css("display","none");
        }else{
            window.alert("当前是最后一页")
            num = l-1;
        }
    })
};
Lbtu()


